package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import com.itheima.utils.AesUtils;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/dangan")
public class DanganController {
    @Autowired
    private  static JedisPool jedisPool;
    @Reference
    private MemberService memberService;
    private static String token;
    @RequestMapping("/gettelephone")
    private  Result co(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if ("t_ss_a".equals(cookie.getName())){
               token = cookie.getValue();
            }
        }
        String decrypt = AesUtils.decrypt(token, "itheima$%^!");
        String[] s = decrypt.split("_");
        String telephone = s[0];


        return Result.success("",telephone);
    }
    @RequestMapping("/findMember")
    public Result findMember(String telephone){
        Member member=memberService.findByTelephone(telephone);

        return Result.success("",member);
    }

}
